home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0"?>
- <bindings xmlns="http://www.mozilla.org/xbl"
- xmlns:html="http://www.w3.org/1999/xhtml"
- xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- xmlns:xbl="http://www.mozilla.org/xbl">
-
- <binding id="jumpAutoComplete">
- <resources>
- <script src="chrome://ybookmarks/content/ybookmarksUtils.js" type="application/x-javascript" />
- </resources>
-
- <handlers>
- <handler event="focus" phase="capturing">
- <![CDATA[
- if (!this.hasAttribute('focused')) {
- this.setAttribute('focused','true');
- }
- ]]>
- </handler>
-
- <handler event="blur" phase="capturing">
- <![CDATA[
- this.removeAttribute('focused');
- this.hideTagSuggestions();
- // this.hideBookmarkSuggestions();
-
- ]]>
- </handler>
-
- <handler event="keypress">
- <![CDATA[
- switch(event.keyCode) {
- case event.DOM_VK_DOWN:
- case event.DOM_VK_UP:
- event.preventDefault();
- break;
- case event.DOM_VK_ESCAPE: //esc
- if (this._areSuggestionsVisible()) {
- event.preventDefault();
- }
- break;
- case event.DOM_VK_RETURN: //enter
- if (this.isSuggestionSelected()) {
- event.preventDefault();
- }
- break;
- case event.DOM_VK_TAB:
- if (this._areSuggestionsVisible()) {
- event.preventDefault();
- }
- break;
- default:
- this._lastEditTags = event.target.value;
- }
- ]]>
- </handler>
-
- <handler event="keyup">
- <![CDATA[
- switch (event.keyCode) {
- case event.DOM_VK_DOWN:
- case event.DOM_VK_UP:
- event.preventDefault();
- break;
- case event.DOM_VK_ESCAPE: //esc
- if (this._areSuggestionsVisible()) {
- this.hideTagSuggestions();
- event.preventDefault();
- }
-
- if(this._areBookmarkSuggestionsVisible()) {
- this.hideBookmarkSuggestions();
- event.preventDefault();
- }
- break;
- case event.DOM_VK_RETURN: //enter
- if (this.isSuggestionSelected()) {
- this.completeTag();
- event.preventDefault();
- }
-
- if(this.isBookmarkSuggestionSelected()) {
- this.openBookmark();
- event.preventDefault();
- }
- break;
- case event.DOM_VK_TAB:
- if (this._areSuggestionsVisible()) {
- if (this._tagSuggestionsPicked < 0) {
- this.selectTagSuggestion(0);
- }
- this.completeTag();
- event.preventDefault();
- }
- break;
- case event.DOM_VK_END:
- case event.DOM_VK_HOME:
- case event.DOM_VK_RIGHT:
- case event.DOM_VK_LEFT:
- case event.DOM_VK_SPACE:
- this.hideTagSuggestions();
- this.hideBookmarkSuggestions();
- break;
- default:
- this.updateTagSuggestions(event.target);
- }
- ]]>
- </handler>
- <handler event="keydown">
- <![CDATA[
- if (this._areSuggestionsVisible()) {
- switch(event.keyCode) {
- case event.DOM_VK_DOWN:
- this.selectTagSuggestion((this._tagSuggestionsPicked + 1) % this._tagSuggestionsLength);
- this.scrollTagSuggestions();
- event.preventDefault();
- break;
- case event.DOM_VK_UP:
- this.selectTagSuggestion((this._tagSuggestionsPicked == 0 || this._tagSuggestionsPicked == -1) ? this._tagSuggestionsLength - 1 : this._tagSuggestionsPicked - 1);
- this.scrollTagSuggestions();
- event.preventDefault();
- break;
- }
- }
-
- if (this._areBookmarkSuggestionsVisible()) {
- switch(event.keyCode) {
- case event.DOM_VK_DOWN:
- this.selectBookmarkSuggestion((this._bookmarkSuggestionsPicked + 1) % this._bookmarkSuggestionsLength);
- this.scrollBookmarkSuggestions();
- event.preventDefault();
- break;
-
- case event.DOM_VK_RETURN: //enter
- if(this.isBookmarkSuggestionSelected()) {
- this.openBookmark();
- event.preventDefault();
- }
- break;
-
- case event.DOM_VK_UP:
- this.selectBookmarkSuggestion((this._bookmarkSuggestionsPicked == 0 || this._bookmarkSuggestionsPicked == -1) ? this._bookmarkSuggestionsLength - 1 : this._bookmarkSuggestionsPicked - 1);
- this.scrollBookmarkSuggestions();
- event.preventDefault();
- break;
- }
- }
-
- ]]>
- </handler>
-
- </handlers>
- <implementation>
- <field name="_stringBundle" />
- <field name="_tagInputBox" />
- <field name="_lastEditTags" />
- <field name="_currentTagText" />
- <field name="_currentTagIndex">0</field>
- <field name="_currentBookmarkIndex">0</field>
- <field name="_tagsTextboxWidth">0</field>
- <field name="_tagSuggestionsPicked">-1</field>
- <field name="_tagSuggestionsLength">0</field>
- <field name="_bookmarkSuggestionsPicked">-1</field>
- <field name="_bookmarkSuggestionsLength">0</field>
- <field name="_tagInputTimeout">250</field>
- <field name="_tagInputTimer" />
- <field name="_lastTagSuggestion" />
- <field name="_lastBookmarkSuggestion" />
- <field name="_suggestionsPopupVisible">false</field>
- <field name="_bookmarkSuggestionsPopupVisible">false</field>
- <field name="_bookmarkTimer" />
- <field name="_bookmarkSuggestions" />
-
- <property name="areSuggestionsVisible" onget="return this._areSuggestionsVisible();" />
-
- <property name="value">
- <setter>
- <![CDATA[
- this._getTagTextBox().value = val;
- ]]>
- </setter>
- <getter>
- <![CDATA[
- var input = this._getTagTextBox();
- if (!input.value) {
- input.value= "";
- }
- return input.value;
- ]]>
- </getter>
- </property>
- <constructor>
- <![CDATA[
- try {
- this._tagInputBox = document.getAnonymousElementByAttribute(this, "anonid", "ybTagAutoComplete-tags");
-
- //window.addEventListener("click", this.onClickListener, false); // cmyang: 2006-12-19 do we need this?
-
- this._stringBundle = document.getAnonymousElementByAttribute(this, "anonid", "ybJumpStrings");
-
- if (!this.getAttribute("popupmaxheight")) {
- this.setAttribute("popupmaxheight", 100);
- }
-
- } catch (e) { yDebug.print("constructor: " +e, YB_LOG_MESSAGE);}
- ]]>
- </constructor>
- <method name="focus">
- <body><![CDATA[
- this._getTagTextBox().focus();
- ]]></body>
- </method>
-
- <method name="_getTagSuggestions">
- <body><![CDATA[
- return document.getAnonymousElementByAttribute(this, "anonid", "ybTagAutoComplete-suggestions");
- ]]></body>
- </method>
-
- <method name="_getBookmarkSuggestions">
- <body><![CDATA[
- return document.getAnonymousElementByAttribute(this, "anonid", "ybBookmarkSuggestions");
- ]]></body>
- </method>
-
- <method name="_getTagTextBox">
- <body><![CDATA[
- return document.getAnonymousElementByAttribute(this, "anonid", "ybTagAutoComplete-tags");
- ]]></body>
- </method>
-
- <method name="_getTagSuggestionsPopup">
- <body><![CDATA[
- return document.getAnonymousElementByAttribute(this, "anonid", "ybTagAutoComplete-popup");
- ]]></body>
- </method>
-
- <method name="_getBookmarkSuggestionsPopup">
- <body><![CDATA[
- return document.getAnonymousElementByAttribute(this, "anonid", "ybBookmarkSuggestionPopup");
- ]]></body>
- </method>
-
- <method name="_areSuggestionsVisible">
- <body><![CDATA[
- return this._suggestionsPopupVisible;
- ]]></body>
- </method>
-
- <method name="_areBookmarkSuggestionsVisible">
- <body><![CDATA[
- return this._bookmarkSuggestionsPopupVisible;
- ]]></body>
- </method>
-
- <method name="_getPopupMaxHeight">
- <body><![CDATA[
- return this.getAttribute("popupmaxheight");
- ]]></body>
- </method>
-
- <method name="isSuggestionSelected">
- <body><![CDATA[
- if (this._areSuggestionsVisible() && this._tagSuggestionsPicked >= 0) {
- return true;
- }
- return false;
- ]]></body>
- </method>
-
- <method name="isBookmarkSuggestionSelected">
- <body><![CDATA[
- if (this._areBookmarkSuggestionsVisible() && this._bookmarkSuggestionsPicked >= 0) {
- return true;
- }
- return false;
- ]]></body>
- </method>
-
- <method name="scrollTagSuggestions">
- <body><![CDATA[
- var suggestionBox = this._getTagSuggestions();
- var row = suggestionBox.firstChild;
-
- var scrollTo = row.boxObject.height * this._tagSuggestionsPicked;
- var scrollBoxObj = suggestionBox.boxObject.
- QueryInterface(Components.interfaces.nsIScrollBoxObject);
- var x = {}, y = {};
-
- scrollBoxObj.getPosition(x, y);
- scrollBoxObj.scrollTo(x.value, scrollTo);
- ]]></body>
- </method>
-
- <method name="scrollBookmarkSuggestions">
- <body><![CDATA[
- try {
- var suggestionBox = this._getBookmarkSuggestions();
-
- var item = suggestionBox.getItemAtIndex(this._bookmarkSuggestionsPicked);
- suggestionBox.ensureElementIsVisible(item);
- } catch(e) {
- //alert(e);
- }
- ]]></body>
- </method>
-
- <method name="clearTagSelection">
- <body><![CDATA[
- try {
- for(var i=0; i < suggestionBox.childNodes.length; i++) {
- suggestionBox.childNodes[i].removeAttribute("highlight");
- }
- } catch(e) { }
- ]]></body>
- </method>
- <method name="clearBookmarkSelection">
- <body><![CDATA[
- try {
- var suggestionBox = this._getBookmarkSuggestions();
- for(var i=0; i < suggestionBox.childNodes.length; i++) {
- suggestionBox.childNodes[i].removeAttribute("highlight");
- }
- } catch(e) { }
- ]]></body>
- </method>
-
- <method name="selectTagSuggestion">
- <parameter name="index" />
- <body><![CDATA[
-
- if(this._bookmarkTimer) {
- clearTimeout(this._bookmarkTimer);
- }
-
- this.clearTagSelection();
-
- if (this._tagSuggestionsLength == 1) index = 0;
- var suggestionBox = this._getTagSuggestions();
- if (this._tagSuggestionsPicked > -1 && suggestionBox.childNodes[this._tagSuggestionsPicked])
- suggestionBox.childNodes[this._tagSuggestionsPicked].removeAttribute("highlight");
- this._tagSuggestionsPicked = index;
-
- if (this._tagSuggestionsPicked > -1)
- suggestionBox.childNodes[this._tagSuggestionsPicked].setAttribute("highlight", "true");
-
- var func = function(me, tag) {
- me.updateBookmarkSuggestions(tag);
- me.showBookmarkSuggestions();
- }
-
- var prefService =
- Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
- var timeout = prefService.getIntPref("extensions.ybookmarks@yahoo.tagSuggestionWait.interval");
-
- if(suggestionBox.childNodes[this._tagSuggestionsPicked].getAttribute("tag")) {
- this._bookmarkTimer = setTimeout(func, timeout, this, suggestionBox.childNodes[this._tagSuggestionsPicked].getAttribute("tag"));
- }
- ]]></body>
- </method>
-
- <method name="selectBookmarkSuggestion">
- <parameter name="index" />
- <body><![CDATA[
- var suggestionBox = this._getBookmarkSuggestions();
-
- this.clearBookmarkSelection();
-
- if (this._bookmarkSuggestionsLength == 1) index = 0;
-
- if (this._bookmarkSuggestionsPicked > -1 && suggestionBox.childNodes[this._bookmarkSuggestionsPicked])
- suggestionBox.childNodes[this._bookmarkSuggestionsPicked].removeAttribute("highlight");
- this._bookmarkSuggestionsPicked = index;
-
- if (this._bookmarkSuggestionsPicked > -1)
- suggestionBox.childNodes[this._bookmarkSuggestionsPicked].setAttribute("highlight", "true");
- ]]></body>
- </method>
-
- <method name="updateTagSuggestions">
- <parameter name="target" />
- <body><![CDATA[
- try {
- if (this._tagInputTimer) {
- clearTimeout(this._tagInputTimer);
- }
-
- if(!this.getCurrentTag() || !this._currentTagIndex) {
- this.hideTagSuggestions();
- return;
- }
-
- if(this._areBookmarkSuggestionsVisible()) {
- this.hideBookmarkSuggestions();
- }
- var func = function(target, me) {
- me._updateTagSuggestions( target.value );
- };
-
- this._tagInputTimer = setTimeout(func, this._tagInputTimeout, target, this);
- } catch (e) { yDebug.print(e);}
- ]]></body>
- </method>
- <method name="_updateTagSuggestions">
- <parameter name="input" />
- <body><![CDATA[
- try {
- if (!this.getCurrentTag() || !this._currentTagIndex) {
- this.hideTagSuggestions();
- return;
- }
-
- var gXUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
-
- var tags = input.split(/\s */);
-
- var currentInput = tags[this._currentTagIndex];
- if (currentInput &&
- this._lastTagSuggestionLength > 0 &&
- currentInput.length >= this._lastTagSuggestionLength &&
- currentInput.indexOf(this._lastTagSuggestion) == 0) {
-
- var suggestionBox = this._getTagSuggestions();
- var element = suggestionBox.firstChild;
- var nElement, tag;
- while (element) {
- nElement = element;
- element = element.nextSibling;
- tag = nElement.getAttribute("tag");
- if (tag.indexOf(currentInput) == -1) {
- suggestionBox.removeChild(nElement);
- }
- }
-
- this._lastTagSuggestion = currentInput;
- }
- else {
-
- var localStore = ( Components.classes[ "@mozilla.org/ybookmarks-store-service;1" ].
- getService( Components.interfaces.nsIYBookmarksStoreService ) );
-
- var suggestions = localStore.getTagSuggestions(currentInput, true);
-
- var suggestionBox = this._getTagSuggestions();
- var suggestion, tag, count;
- var row, text;
-
- //remove everything in type down
- while (suggestionBox.firstChild) {
- suggestionBox.removeChild(suggestionBox.firstChild);
- }
-
- //add stuff in
- outer: for (var i = 0; i < suggestions.length; i++) {
- if(i == 15) break;
-
- suggestion = suggestions.queryElementAt(i, Components.interfaces.nsIWritablePropertyBag);
- tag = suggestion.getProperty("tag");
- count = suggestion.getProperty("count");
-
- //row = document.createElementNS(gXUL_NS, "row");
- /**
- * Create text heading
- */
- if(i == 0) {
- headText = document.getAnonymousElementByAttribute(this, "anonid", "ybTagSuggestHeading");
- headText.setAttribute("class", "suggestionHeading");
- headText.setAttribute("value", this._stringBundle.getString("extensions.ybookmarks.ybJump.suggestionHeading"));
- }
-
- text = document.createElementNS(gXUL_NS, "text");
- text.setAttribute("color", ((i%2)? "white" : "grey"));
- text.setAttribute("class", "suggestion-tag");
- text.setAttribute("value", tag + " (" + count + ")");
- text.setAttribute("tag", tag);
- text.addEventListener("click", this.completeTag, false);
- text.addEventListener("mouseover", function() { this.setAttribute("highlight", "true"); }, false);
- text.addEventListener("mouseout", function() { this.removeAttribute("highlight"); }, false);
-
- suggestionBox.appendChild(text);
- }
-
- if (currentInput) {
- this._lastTagSuggestion = currentInput;
- } else {
- this._lastTagSuggestion = "";
- }
- }
-
- this._tagSuggestionsLength = suggestionBox.childNodes.length;
-
-
- if (suggestionBox.childNodes.length > 0) {
- this.showTagSuggestions();
- } else {
- this.hideTagSuggestions();
- }
- } catch(e) { yDebug.print("_updateTagSuggestions(): " + e, YB_LOG_MESSAGE);}
- ]]></body>
- </method>
-
- <method name="showTagSuggestions">
- <body><![CDATA[
- try {
- var suggestionBox = this._getTagSuggestions();
- var suggestionPopup = this._getTagSuggestionsPopup();
- var inputBox = this._getTagTextBox();
-
- suggestionBox.style.overflow = "-moz-scrollbars-none";
- if(ybookmarksUtils.getFFMajorVersion() > 2) {
- var posY = this._tagInputBox.boxObject.screenY + this._tagInputBox.boxObject.height - 3;
- }
- else {
- var posY = document.documentElement.boxObject.y + this._tagInputBox.boxObject.y + this._tagInputBox.boxObject.height - 3;
- }
-
- //set the position X of the suggestion box
- var pos = 0;
- var tags = this.getUserInputTags("array");
-
- for(var i = 0; i < this._currentTagIndex; i++) {
- pos += tags[i].length + 1;
- }
- var text = this.getUserInputTags("string").substr(0, pos);
-
- var invisibleTags = document.getAnonymousElementByAttribute(this, "anonid", "ybTagAutoComplete-invisible-tags");
- var invisibleBox = document.getAnonymousElementByAttribute(this, "anonid", "ybTagAutoComplete-invisible-box");
- invisibleTags.value = text;
- invisibleBox.hidden = false;
- var invisibleTagsWidth = invisibleTags.boxObject.width;
- invisibleBox.hidden = true;
- invisibleTags.value = "";
-
- var offsetX = 2;
- if ((invisibleTagsWidth + suggestionBox.boxObject.width) > this._tagInputBox.boxObject.width) {
- offsetX += this._tagInputBox.boxObject.width - suggestionBox.boxObject.width;
- } else {
- offsetX += invisibleTagsWidth;
- }
-
- if(ybookmarksUtils.getFFMajorVersion() > 2) {
- var posX = this._tagInputBox.boxObject.screenX + offsetX;
- }
- else {
- var posX = this._tagInputBox.boxObject.x + offsetX;
- }
-
- if(this._areBookmarkSuggestionsVisible()) {
- this.hideBookmarkSuggestions();
- }
- document.popupNode = document.documentElement; // needed for some bug
- //reduce the height of scrollbox
- suggestionBox.setAttribute("maxheight", this._getPopupMaxHeight() - 70);
- suggestionPopup.showPopup(document.documentElement, posX, posY, "popup");
- this._suggestionsPopupVisible = true;
-
- //make first matching tag selected by default
- this.selectTagSuggestion(0);
-
- //figure out if overloaded
- if (suggestionBox.boxObject.height >= this._getPopupMaxHeight() - 70) {
- suggestionBox.style.overflow = "-moz-scrollbars-vertical";
- yDebug.print("added bars");
- }
-
- } catch (e) { yDebug.print("Exception from jump autocomplete: "+e, YB_LOG_MESSAGE);}
- ]]></body>
- </method>
-
- <method name="hideTagSuggestions">
- <body><![CDATA[
-
- var suggestionPopup = this._getTagSuggestionsPopup();
- suggestionPopup.hidePopup();
- this._suggestionsPopupVisible = false;
- this._tagSuggestionsPicked = -1;
- this._tagSuggestionsLength = 0;
-
- if (this._tagInputTimer) {
- clearTimeout(this._tagInputTimer);
- this._tagInputTimer = null;
- }
- ]]></body>
- </method>
-
- <method name="getElementById">
- <parameter name="format" />
- <body><![CDATA[
- var tags = this._tagInputBox.value;
- if (format == "string") {
- return tags;
- }
- else {
- var tagArray = tags.split(/\s */);
- return tagArray;
- }
- ]]></body>
- </method>
-
- <method name="setUserInputTags">
- <parameter name="inputTagArray" />
- <body><![CDATA[
- this._tagInputBox.value = inputTagArray.join(" ") + " ";
- ]]></body>
- </method>
-
- <method name="completeTag">
- <parameter name="event" />
- <body><![CDATA[
- try {
- var boundElt;
- var selectedTag = "";
-
- if (event) {
- selectedTag = event.target.getAttribute("tag");
- boundElt = event.target.parentNode.parentNode.parentNode.parentNode;
- } else {
- var suggestionBox = this._getTagSuggestions();
- selectedTag = suggestionBox.childNodes[this._tagSuggestionsPicked].getAttribute("tag");
- boundElt = this;
- }
-
- var inputTagArray = boundElt.getUserInputTags("array");
-
- if (boundElt._currentTagIndex) {
- var curTag = inputTagArray[ boundElt._currentTagIndex ];
- var plusIndex = curTag.lastIndexOf( '+' );
- if( plusIndex > -1 ) {
- // we need to add the tag at the end of existing string
- selectedTag = curTag.substr( 0, plusIndex + 1 ) + selectedTag;
- }
- inputTagArray[ boundElt._currentTagIndex ] = selectedTag;
- }
-
- boundElt.setUserInputTags( inputTagArray );
- boundElt.hideTagSuggestions();
- } catch(e) { }
- ]]></body>
- </method>
-
- <method name="getCurrentTag">
- <parameter name="" />
- <body><![CDATA[
- var tags = this.getUserInputTags("string");
- if (tags == this._lastEditTags) return true;
- if (tags == "") return false;
-
- this._currentTagText = "";
- this._currentTagIndex = 0;
-
- var tagArray = tags.toLowerCase().split(/\s */);
- var oldArray = this._lastEditTags.toLowerCase().split(/\s */);
- var matched = false;
- var currentTags = new Array();
- for (t in tagArray) {
- for (o in oldArray) {
- if (typeof oldArray[o] == "undefined") {
- yDebug.print("remove the " + o + ":" + oldArray[o]);
- oldArray.splice(o,1);
- break;
- }
- if (tagArray[t] == oldArray[o]) {
- matched = true;
- oldArray.splice(o,1);
- break;
- }
- }
- if (!matched) {
- currentTags[currentTags.length] = t;
- }
- matched = false;
- }
-
- // more than one word changed... abort
- if(currentTags.length > 1) {
- this.hideTagSuggestions();
- return false;
- }
-
- this._currentTagText = tagArray[currentTags[0]];
- this._currentTagIndex = currentTags[0];
-
- return true;
- ]]></body>
- </method>
-
- <method name="onClickListener">
- <parameter name="event" />
- <body><![CDATA[
- try {
- var gXUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
- if (event.target.nodeName != "jumpautocomplete") {
- var tacs = document.getElementsByTagNameNS(gXUL_NS, "jumpautocomplete");
- for (var i=0; i < tacs.length; i++) {
- var tac = tacs.item(i);
- if (tac._areSuggestionsVisible()) {
- tac.hideTagSuggestions();
- }
- }
- }} catch(e) { yDebug.print("onClickListener(): " + e);}
- ]]></body>
- </method>
-
- <method name="getUserInputTags">
- <parameter name="format" />
- <body><![CDATA[
- var tags = this._tagInputBox.value;
- if (format == "string") {
- return tags;
- }
- else {
- var tagArray = tags.split(/\s */);
- return tagArray;
- }
- ]]></body>
- </method>
-
- <method name="updateBookmarkSuggestions">
- <parameter name="tag"/>
- <body>
- <![CDATA[
- try {
-
- if(!this._currentTagText) return;
-
- var gXUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
- var row, title, url;
-
- var suggestionBox = this._getBookmarkSuggestions();
-
- //update list box
- var localStore = ( Components.classes[ "@mozilla.org/ybookmarks-store-service;1" ].
- getService( Components.interfaces.nsIYBookmarksStoreService ) );
-
- this._bookmarkSuggestions = localStore.getBookmarks(tag, {});
-
- //remove everything in type down
- while (suggestionBox.firstChild) {
- suggestionBox.removeChild(suggestionBox.firstChild);
- }
-
- for(var i=0; i < this._bookmarkSuggestions.length; i++) {
- /**
- * Create text heading
- */
- if(i == 0) {
- headText = document.getAnonymousElementByAttribute(this, "anonid", "ybBookmarkSuggestHeading");
- headText.setAttribute("class", "suggestionHeading");
- headText.setAttribute("value", this._stringBundle.getFormattedString("extensions.ybookmarks.ybJump.bookmarkSuggestionHeading", [tag]));
- }
-
- var maxlength = 30;
- row = document.createElementNS(gXUL_NS, "richlistitem");
- var vbox = document.createElementNS(gXUL_NS, "vbox");
- title = document.createElementNS(gXUL_NS, "text");
- title.setAttribute("value", (this._bookmarkSuggestions[i].name.length > maxlength) ? this._bookmarkSuggestions[i].name.substr(0, maxlength) + "..." : this._bookmarkSuggestions[i].name);
- title.setAttribute("class", "suggestion-tag-title");
-
- url = document.createElementNS(gXUL_NS, "text");
- url.setAttribute("value", (this._bookmarkSuggestions[i].url.length > maxlength) ? this._bookmarkSuggestions[i].url.substr(0, maxlength) + "..." : this._bookmarkSuggestions[i].url);
-
-
- row.setAttribute("color", ((i%2)? "white" : "grey"));
- row.setAttribute("class", "suggestion-tag");
- row.setAttribute("url", this._bookmarkSuggestions[i].url);
- row.addEventListener("mousedown", this.selectBookmark, false);
- row.addEventListener("mouseover", function() { this.setAttribute("highlight", "true"); }, false);
- row.addEventListener("mouseout", function() { this.removeAttribute("highlight"); }, false);
-
- vbox.setAttribute("minwidth", 210);
-
- vbox.appendChild(title);
- vbox.appendChild(url);
- row.appendChild(vbox);
-
- suggestionBox.appendChild(row);
- }
-
- this._bookmarkSuggestionsLength = suggestionBox.childNodes.length;
- } catch (e) { }
- ]]>
- </body>
- </method>
- <method name="showBookmarkSuggestions">
- <body><![CDATA[
- try {
-
- if(!this._currentTagText) return;
-
- this.completeTag();
- this.hideTagSuggestions();
-
- var suggestionBox = this._getBookmarkSuggestions();
- var suggestionPopup = this._getBookmarkSuggestionsPopup();
- var inputBox = this._getTagTextBox();
-
- if(ybookmarksUtils.getFFMajorVersion() > 2) {
- var posY = this._tagInputBox.boxObject.screenY + this._tagInputBox.boxObject.height - 3;
- }
- else {
- var posY = document.documentElement.boxObject.y + this._tagInputBox.boxObject.y + this._tagInputBox.boxObject.height - 3;
- }
-
- //set the position X of the suggestion box
- var offsetX = 2;
-
- if(ybookmarksUtils.getFFMajorVersion() > 2) {
- var posX = this._tagInputBox.boxObject.screenX + offsetX;
- }
- else {
- var posX = this._tagInputBox.boxObject.x + offsetX;
- }
-
- this._bookmarkSuggestionsPopupVisible = true;
- document.popupNode = document.documentElement; // needed for some bug
- //reduce the height of scrollbox
- suggestionBox.setAttribute("maxheight", this._getPopupMaxHeight() - 70);
- suggestionPopup.showPopup(document.documentElement, posX, posY, "popup");
-
- } catch (e) { }
- ]]></body>
- </method>
-
- <method name="openBookmark">
- <body><![CDATA[
- var suggestionBox = this._getBookmarkSuggestions();
-
- if(this._bookmarkSuggestionsPicked > -1 && suggestionBox.childNodes[this._bookmarkSuggestionsPicked] && this._bookmarkSuggestions[this._bookmarkSuggestionsPicked]) {
- var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
- .getService(Components.interfaces.nsIWindowMediator);
- var mainWindow = wm.getMostRecentWindow("navigator:browser");
- mainWindow.getBrowser().selectedTab = mainWindow.getBrowser().addTab(this._bookmarkSuggestions[this._bookmarkSuggestionsPicked].url);
- }
-
- this.hideBookmarkSuggestions();
- window.close();
- ]]></body>
- </method>
-
- <method name="selectBookmark">
- <parameter name="event"/>
- <body><![CDATA[
- try {
- if(event.target.tagName == "text") {
- var row = event.target.parentNode.parentNode;
- }
- else if(event.target.tagName == "vbox") {
- var row = event.target.parentNode;
- }
- else if(event.target.tagName == "richlistitem") {
- var row = event.target;
- }
-
- var url = row.getAttribute("url");
-
-
- var bundleElm = row.parentNode.parentNode.parentNode.parentNode;
-
- if(url) {
- var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
- .getService(Components.interfaces.nsIWindowMediator);
- var mainWindow = wm.getMostRecentWindow("navigator:browser");
- mainWindow.getBrowser().selectedTab = mainWindow.getBrowser().addTab(url);
- }
-
- bundleElm.hideBookmarkSuggestions();
- window.close();
- } catch(e) { }
- ]]></body>
- </method>
-
-
- <method name="hideBookmarkSuggestions">
- <body><![CDATA[
- this._bookmarkSuggestionsPopupVisible = false;
- var suggestionPopup = this._getBookmarkSuggestionsPopup();
- suggestionPopup.hidePopup();
- ]]></body>
- </method>
- </implementation>
- <content>
- <xul:stringbundleset>
- <xul:stringbundle id="ybJumpStrings" anonid="ybJumpStrings" src="chrome://ybookmarks/locale/ybJump.properties"/>
- </xul:stringbundleset>
- <xul:popupset>
- <xul:popup anonid="ybTagAutoComplete-popup" ignorekeys="true" xbl:inherits="maxheight=popupmaxheight">
- <xul:label anonid="ybTagSuggestHeading" value="" maxheight="20" minwidth="250"/>
- <xul:scrollbox anonid="ybTagAutoComplete-suggestions" orient="vertical" maxheight="10"/>
- </xul:popup>
- <xul:popup anonid="ybBookmarkSuggestionPopup" ignorekeys="true" xbl:inherits="maxheight=popupmaxheight">
- <xul:label anonid="ybBookmarkSuggestHeading" value="" maxheight="20" minwidth="250"/>
- <xul:richlistbox anonid="ybBookmarkSuggestions" class="bookmarkSuggestionsList">
- </xul:richlistbox>
- </xul:popup>
- </xul:popupset>
- <xul:textbox anonid="ybTagAutoComplete-tags" xbl:inherits="onfocus,onblur,tabindex,cols,rows,flex,value,accesskey"/>
- <xul:hbox anonid="ybTagAutoComplete-invisible-box" hidden="true">
- <xul:label anonid="ybTagAutoComplete-invisible-tags"/>
- </xul:hbox>
-
- </content>
- </binding>
- </bindings>